<include file="public/layout" />
<script src="__ROOT__/public/static/js/layer/laydate/laydate.js"></script>
<body style="background-color: #FFF; overflow: auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3>优惠券管理 - 编辑优惠券</h3>
                <h5>网站系统优惠券管理</h5>
            </div>
        </div>
    </div>
    <form class="form-horizontal" id="handleposition" method="post">
        <input type="hidden" name="id" value="{$coupon.id}"/>
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>优惠券名称</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="name" name="name" value="{$coupon.name}" class="input-txt">
                    <span class="err" id="err_name"></span>
                    <p class="notic">请填写优惠券名称</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>优惠券面额</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="money" name="money"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" value="{$coupon.money}" class="input-txt">
                    <span class="err" id="err_money"></span>
                    <p class="notic">优惠券可抵扣金额</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>消费金额</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="condition" name="condition" value="{$coupon.condition}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" class="input-txt">
                    <span class="err" id="err_condition"></span>
                    <p class="notic">订单需满足的最低消费金额(必需为整数)才能使用</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>发放数量</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="createnum" name="createnum" value="{$coupon.createnum}" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" class="input-txt">
                    <span class="err" id="err_createnum"></span>
                    <p class="notic">发放数量限制(默认为0则无限制)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>发放类型</label>
                </dt>
                <dd class="opt ctype">
                    <input name="type" type="radio" value="0" <if condition="$coupon['type'] eq 0">checked</if> ><label>下单赠送</label>
                    <input name="type" type="radio" value="1" <if condition="$coupon['type'] eq 1">checked</if> ><label>指定发放</label>
                    <input name="type" type="radio" value="2" <if condition="$coupon['type'] eq 2">checked</if> ><label>免费领取</label>
                    <input name="type" type="radio" value="3" <if condition="$coupon['type'] eq 3">checked</if> ><label>线下发放</label>
                </dd>
            </dl>
            <dl class="row timed">
                <dt class="tit">
                    <label><em>*</em>发放起始日期</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="send_start_time" name="send_start_time" value="{$coupon.send_start_time|date='Y-m-d H:i:s',###}"  class="input-txt">
                    <span class="err" id="err_send_start_time"></span>
                    <p class="notic">发放起始日期</p>
                </dd>
            </dl>
            <dl class="row timed">
                <dt class="tit">
                    <label><em>*</em>发放结束日期</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="send_end_time" name="send_end_time" value="{$coupon.send_end_time|date='Y-m-d H:i:s',###}" class="input-txt">
                    <p class="notic">发放结束日期</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>使用起始日期</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="use_start_time" name="use_start_time" value="{$coupon.use_start_time|date='Y-m-d H:i:s',###}" class="input-txt">
                    <span class="err" id="err_use_start_time"></span>
                    <p class="notic">使用起始日期</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>使用结束日期</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="use_end_time" name="use_end_time" value="{$coupon.use_end_time|date='Y-m-d H:i:s',###}" class="input-txt">
                    <p class="notic">使用结束日期</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label>状态</label>
                </dt>
                <dd class="opt">
                    <input name="status" type="radio" value="1" <if condition="$coupon['status'] eq 1">checked</if> ><label>有效</label>
                    <input name="status" type="radio" value="0" <if condition="$coupon['status'] eq 0">checked</if> ><label>无效</label>
                </dd>
            </dl>
            <div class="bot"><a onclick="verifyForm();" class="ncap-btn-big ncap-btn-green">确认提交</a></div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $('.ctype ').find('input[type="radio"]').click(function(){
        if($(this).val() == 0 || $(this).val() == 4){
            $('.timed').hide();
        }else{
            $('.timed').show();
        }
    })

    $(document).ready(function(){
        $('.ctype ').find('input[type="radio"]:checked').trigger('click');
        $('#send_start_time').layDate();
        $('#send_end_time').layDate();
        $('#use_start_time').layDate();
        $('#use_end_time').layDate();
    })

    function verifyForm(){
        $('span.err').show();
        $.ajax({
            type: "POST",
            url: "{:U('Admin/Coupon/coupon_info')}",
            data: $('#handleposition').serialize(),
            dataType: "json",
            error: function () {
                layer.alert("服务器繁忙, 请联系管理员!");
            },
            success: function (data) {
                if (data.status == 1) {
                    layer.msg(data.msg, {icon: 1});
                    location.href = "{:U('Admin/Coupon/index')}";
                } else {
                    layer.msg(data.msg, {icon: 2});
                    $.each(data.result, function (index, item) {
                        $('#err_' + index).text(item).show();
                    });
                }
            }
        });
    }

</script>
</body>
</html>